package com.sr.recitewords.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sr.recitewords.common.enums.BizExceptionEnum;
import com.sr.recitewords.common.vo.GeneralResult;
import com.sr.recitewords.datasource.entities.SysLanguage;
import com.sr.recitewords.datasource.entities.SysLanguageCategory;
import com.sr.recitewords.datasource.entities.SysUser;
import com.sr.recitewords.datasource.req.LoginReq;
import com.sr.recitewords.datasource.req.SysLanguagePageReq;
import com.sr.recitewords.datasource.resp.LoginResp;
import com.sr.recitewords.datasource.vo.SysUserVo;
import com.sr.recitewords.exception.BizException;
import com.sr.recitewords.service.redis.RedisService;
import com.sr.recitewords.service.sysLanguage.SysLanguageService;
import com.sr.recitewords.service.sysLanguageCategory.SysLanguageCategoryService;
import com.sr.recitewords.service.user.SysUserService;
import com.sr.recitewords.utils.BaseResponseInfo;
import com.sr.recitewords.utils.MD5EncryptUtils;
import com.sr.recitewords.utils.RandImageUtil;
import com.sr.recitewords.utils.ToolUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@RestController
@RequestMapping(value = "/sysLanguage")
@Api(tags = {"语种管理"})
public class SysLanguageController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(SysLanguageController.class);

    @Resource
    private SysLanguageService sysLanguageService;
    @Resource
    private SysLanguageCategoryService sysLanguageCategoryService;
    @Resource
    private RedisService redisService;

    @ApiOperation(value = "获取语种分页")
    @RequestMapping(value = "/getSysLanguagePage", method = RequestMethod.POST)
    public GeneralResult<Page<SysLanguage>> getSysLanguagePage(@RequestBody SysLanguagePageReq req) {
        Page<SysLanguage> sysLanguagePage = sysLanguageService.getSysLanguagePage(req);
        return GeneralResult.genSuccessResult(sysLanguagePage);
    }

    @ApiOperation(value = "添加语种")
    @RequestMapping(value = "/addSysLanguage", method = RequestMethod.POST)
    public GeneralResult<String> addSysLanguage(@RequestBody SysLanguage SysLanguage) {
        SysLanguage.setCreateUserId(getUserId());
        boolean b = sysLanguageService.addSysLanguage(SysLanguage);
        return GeneralResult.genSuccessResult(b ? "添加成功" : "添加失败");
    }

    @ApiOperation(value = "批量添加语种")
    @RequestMapping(value = "/addSysLanguageList", method = RequestMethod.POST)
    public GeneralResult<String> addSysLanguageList(@RequestBody List<SysLanguage> languageList) {
        for (SysLanguage sysLanguage : languageList) {
            sysLanguage.setCreateUserId(getUserId());
        }
        boolean b = sysLanguageService.addSysLanguageList(languageList);
        return GeneralResult.genSuccessResult(b ? "添加成功" : "添加失败");
    }

    @ApiOperation(value = "添加某个语种的类别")
    @RequestMapping(value = "/addSysLanguageCategory", method = RequestMethod.POST)
    public GeneralResult<String> addSysLanguageCategory(@RequestBody SysLanguageCategory sysLanguageCategory) {
        sysLanguageCategory.setCreateUserId(getUserId());
        boolean b = sysLanguageCategoryService.addSysLanguageCategory(sysLanguageCategory);
        return GeneralResult.genSuccessResult(b ? "添加成功" : "添加失败");
    }

    @ApiOperation(value = "批量添加某个语种的类别")
    @RequestMapping(value = "/addSysLanguageCategoryList", method = RequestMethod.POST)
    public GeneralResult<String> addSysLanguageCategoryList(@RequestBody List<SysLanguageCategory> sysLanguageCategoryList) {
        for (SysLanguageCategory sysLanguageCategory : sysLanguageCategoryList) {
            sysLanguageCategory.setCreateUserId(getUserId());
        }
        boolean b = sysLanguageCategoryService.addSysLanguageCategoryList(sysLanguageCategoryList);
        return GeneralResult.genSuccessResult(b ? "添加成功" : "添加失败");
    }


}
